const express = require('express')
const router = express.Router()
const pestdiseaseDao = require('../database/pestdiseaseDao')

router.get('/getPestDiseaseData',async (req,res) => {
  let farmlandId = req.query.farmlandId
  try{
    let result = await pestdiseaseDao.getPestData(farmlandId)
    res.send({
      code:200,
      msg:'获取成功',
      data:result
    })
  }catch(err){
    res.send({
      code:400,
      msg:'获取失败',
      data:err
    })
  }
})
router.post('/addPestDiseaseData',async (req,res) => {
  let { farmland_id,type,severity,area,time }  = req.body
  try{
    let result = await pestdiseaseDao.addPestData(farmland_id,type,severity,area,time)
    res.send({
      code:200,
      msg:'获取成功',
      data:result
    })
  }catch(err){
    res.send({
      code:400,
      msg:'获取失败',
      data:err
    })
  }
})
router.put('/modifyPestDiseaseData',async (req,res) => {
  let { id,farmland_id,type,severity,area,time }  = req.body
  try{
    let result = await pestdiseaseDao.modifyPestData(id,farmland_id,type,severity,area,time)
    res.send({
      code:200,
      msg:'获取成功',
      data:result
    })
  }catch(err){
    res.send({
      code:400,
      msg:'获取失败',
      data:err
    })
  }
})
router.get('/deletePestDiseaseData',async (req,res) => {
  let id  = req.query.id
  try{
    let result = await pestdiseaseDao.deletePestData(id)
    res.send({
      code:200,
      msg:'获取成功',
      data:result
    })
  }catch(err){
    res.send({
      code:400,
      msg:'获取失败',
      data:err
    })
  }
})
module.exports = router